package com.info.dpunified.dpgen.dataaccess;

import java.sql.Types;
import java.util.List;

import javax.sql.DataSource;

import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.core.JdbcTemplate;

public class ReportDAO {

	private JdbcTemplate jdbcTemplate;

	public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}

	/**
	 * Specify the statement
	 */
	private static final String FETCH_REPORTS_QUERY = "SELECT MONTH FROM dpuradardefect WHERE YEAR = ?" +
			" AND PROJECTCODE = ?";

	
	public void setDataSource(DataSource dataSource) {
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}
	
	public List<String> fetchMonthsSubmmited(String year,String projectCode)
	{
		return this.getJdbcTemplate().queryForList(FETCH_REPORTS_QUERY, new String[]{year,projectCode},new int[]{Types.INTEGER,Types.VARCHAR}, String.class);
	}
	
	public static void main(String args[])
	{
		XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("spring-context.xml")) ;
		ReportDAO reportDAO =(ReportDAO) beanFactory.getBean("reportDAO");
		System.out.println(reportDAO.fetchMonthsSubmmited("2000", "rojectCode"));
	}
	
}
